/*jquery*/
$.extend({
   includePath: '',
   include: function(file) {
      var files = typeof file == "string" ? [file]:file;
      for (var i = 0; i < files.length; i++) {
          var name = files[i].replace(/^\s|\s$/g, "");
          var att = name.split('.');
          var ext = att[att.length - 1].toLowerCase();
          var isCSS = ext == "css";
          var tag = isCSS ? "link" : "script";
          var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
          var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'";
          if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
      }
 }
});
function errorAlert(msg,obj){
	alert(msg);
	$(obj).focus();
}
function showSysMsg(msg){
	if(msg){
		$(".sys-msg-info").html("<div class=\"msg-tip icon-tip\"></div><div>"+msg+"</div>");
		$(".sys-msg-info").show();
	}
}
function showSuccessMsg(msg){
	var msg = '<div class="panel window" id="successMsg" style="display: none; width: 238px; right: 0px; z-index: 9002; bottom: 0px; "><div class="panel-header panel-header-noborder window-header" style="width: 238px; "><div class="panel-title">Config Success</div><div class="panel-tool"><a class="panel-tool-close" href="javascript:void(0)"></a></div></div><div class="messager-body panel-body panel-body-noborder window-body" title="" id="" style="width: 216px; height: 55px; ">Message will be closed after 5 seconds.</div></div>';
	$(document).append(msg);
	$("#successMsg").show();
	$(".panel-tool-close").click(function(){$("#successMsg").hide();})
	setTimeout(function(){$("#successMsg").hide();},5000);
}
/*util code*/
function utf8_strlen(string){
	var str_len = 0;
	for (var i = 0; i < string.length; i++)
	{		
		if(string.charCodeAt(i) < 256)
			str_len++;

	   	var str = string.charAt(i);
		var pat2 = /[\u4e00-\u9fa5]/g;
		var str_match_pat2 = str.match(pat2);
		if (str_match_pat2){
			str_len = str_len + 3;
		}
	}
	return str_len;
}
function ajaxErrorLoad(mod){}
function getStrSplitObj(str){ 
	var strArr = str.split(",");
	var strObjArr = new Array();
	for(var i=0;i<strArr.length;i++){
		strObjArr[i] = "#"+strArr[i]
	}
	return strObjArr;
}

/*
*form check click toggle html hide and show
*srcObjId:
*/
function chkToggle(src, dst, state){
	if( $("#"+src).is(":checked") )
		$("#"+dst).show();
	else
		$("#"+dst).hide();
	$("#"+src).click(function(){
		if( $("#"+src).is(":checked") )
			$("#"+dst).show();
		else
			$("#"+dst).hide();
	})
}
function radioToggle(src,dst){
	var radio=0;
	$("input[name="+src+"]").each(function(i){
		if($(this).attr('checked')){
			if(dst[i] != '')
				$(getStrSplitObj(dst[i]).toString()).show()
			radio++;
		}
		else{
			if(dst[i] != ''){
				$(getStrSplitObj(dst[i]).toString()).hide();
			}
		}
		$(this).click(function(){
			for(var c=0,l=dst.length;c<l;c++)
			{
				if(dst[c] != ''){
					$(getStrSplitObj(dst[c]).toString()).hide();
				}
			}
			if(dst[i] != '')	
				$(getStrSplitObj(dst[i]).toString()).show()
		})
	})
	if(radio==0){
		$("input[name="+src+"]").get(0).checked=true;
		$(getStrSplitObj(dst[0]).toString()).show()		
	}

}
function selectToggle(src,dst){
	var obj = $("select[name="+src+"]").get(0);
	var leng = obj.length;
	for(var i=0;i<leng;i++){
		if(obj.options[i].selected)
			$("#"+dst[i]).show()
		else
			$("#"+dst[i]).hide()
	}
	$("select[name="+src+"]").click(function(){
		obj = $(this).get(0);
		for(var i=0;i<leng;i++){
			if(obj.options[i].selected)
				$("#"+dst[i]).show()
			else
				$("#"+dst[i]).hide()
		}
	})
}
function input_text_event(id)
{
	var arr = id.split(',');
	for( var i=0,l=arr.length;i<l;i++ ){
		var item=$("#"+arr[i]);
		item.attr("src",item.attr("value"));
		item.focus(function(){
			if(item.val()==item.attr("src"))
			{
				item.val("");
				item.removeClass("inner_prompt");
			}
		});

		item.blur(function(){
			if(item.val()=="")
			{
				item.val(item.attr("src"));
				item.addClass("inner_prompt");
			}
		});
	}
	return;
}
function data_replace(data,value)
{
	var data = data.replace('value=\''+value+'\'','value=\''+value+'\' SELECTED');
	return data;
}
function get_operate_link( v, data, module, ref , edit_flag ){
	var del_link = '',edit_link = '';
	del_link = (ref>0)?'<a href="javascript:void(0)" onclick="alert(\'删除错误，被引用或为预定义不能删除\')"><img src="../public/images/default/icons/icon_del_disable.gif"></a>':'<a href="javascript:void(0)" onclick="if(confirm(\'确定删除？\')) window.location=\'?g='+module+'_delete&name='+data.name+'\'"><img src="../public/images/default/icons/icon_del.gif" alt="删除" title="删除"></a>';
	edit_link = (ref>0 && edit_flag == true)?'<a href="javascript:void(0)" onclick="alert(\'编辑错误，被引用或为预定义不能编辑\')"><img src="../public/images/default/icons/icon_edit_disable.gif"></a>':'<a href="?g='+module+'_edit&name='+data.name+'" class="editLink"><img src="../public/images/default/icons/icon_edit.gif" alt="编辑" title="编辑"></a>';
	return edit_link + del_link;
}
function get_edit_link( v, data, module ){
	return '<a href="?g='+module+'_edit&name='+data.name+'" class="editLink"><img src="./images/default/icons/icon_edit.gif" alt="编辑" title="编辑"></a>';
}
function get_delete_link( v, data, module ){
	return '<a href="?g='+module+'_delete&name='+data.name+'" class="delLink"><img src="./images/default/icons/icon_delete.gif" alt="删除" title="删除"></a>';
}
function get_state( v ){
	return (v==1)? '<img src="./images/default/icons/icon_enable.gif">':'<img src="./images/default/icons/icon_disable.gif">';
}
function load_objdata(data){
	var loadData={group:[]};
	if(data&&data.group)
	{
		if(data.group.length)
			loadData.group = data.group
		else
			loadData.group[0] = data.group
	}
	return loadData;
}
function json_to_string (obj){   
        var THIS = this;    
        switch(typeof(obj)){   
            case 'string':   
                return '"' + obj.replace(/(["\\])/g, '\\$1') + '"';   
            case 'array':   
                return '[' + obj.map(THIS.json_to_string).join(',') + ']';   
            case 'object':   
                 if(obj instanceof Array){   
                    var strArr = [];   
                    var len = obj.length;   
                    for(var i=0; i<len; i++){
                        strArr.push(THIS.json_to_string(obj[i]));   
                    }   
                    return '[' + strArr.join(',') + ']';   
                }else if(obj==null){   
                    return 'null';   
  
                }else{   
                    var string = [];   
                    for (var property in obj) 
					{
						if(property == 'ck' || property == 'operate' || property == 'index' )
							continue;
						
						if(obj[property])
							string.push(THIS.json_to_string(property) + ':' + THIS.json_to_string(obj[property]));
					}
                    return '{' + string.join(',') + '}';   
                }   
            case 'number':   
                return obj;   
            case false:   
                return obj;   
        }
    }

function name_in_array(needle,array){
	if(array.length>0){
		for(var i=0,l=array.length;i<l;i++){
			if(needle==array[i].name)
			{
				return true;
			}
		}
	}
	else
		return false;
	return false;
}
function addr_in_array(needle,array){
	if(array.length>0){
		for(var i=0,l=array.length;i<l;i++){
			if(needle==array[i].address)
			{
				return true;
			}
		}
	}
	else
		return false;
	return false;
}
function string_to_json(obj){   
        return eval_r('(' + obj + ')');   
}
function getTrafficUnit(string){
	var string = parseInt(string);
	if(string>0&&string<1000)
	{
		return string+'kb';
	}
	else 
	if(string>=1000&&string<1000000)
	{
		return string/1000+'M';
	}
	else 
	if(string>=1000000&&string<=1000000000)
	{
		return string/1000000+'G';
	}
	else
		return string+'kb';
}


$.fn.easyTable = function(options) {

	//局部变量
	var _mine = $(this); //div.list-Box
	//利用box来判断是否已经初始化,ture则进行初始化
	if( _mine.attr( 'box' ) == undefined ){
		//添加标示
		_mine.attr( 'box' , 'easytable' );

		// 默认参数
		// 默认高300,宽100%,均分宽度,分页信息为1
		var defaults = {
			width			: "100%",
			height			: "300px",
			limit			: 0,
			widtharray		: [],
			page			: {"page":1,"count":20,"total":1,"link":"#"},

			line_hight		: 24
		};
		options = $.extend(defaults,options);

		// 规范宽度 表头/内容 table
		var _mine_firstTable = _mine.find( "table:first" );
		var _mine_lastTables = _mine.find( "table:last" );
		// 滚动部分
		var _mineHead = _mine.find( ".css_head" );
		var _mineScroll = _mine.find( ".css_scroll" );

		// 设置表格高度
		// 首先接纳限制行数,然后接纳高度
		var setHeight = 0;
		if ( options.limit != 0 ) {
			setHeight = parseInt( options.limit ) * options.line_hight;
		}else{
			setHeight = parseInt( options.height.replace(/px/g,'') );
		}
		_mineHead.css( "height" , (options.line_hight+2) + "px" );
		_mineScroll.css( {"width":options.width + "px","height":setHeight + "px","overflow-y":"auto","overflow-x":"hidden"} );

		// 设置表格宽度
		// 首先设置总宽,在设置其个别宽度
		_mine_firstTable.css( "width" , options.width + "px" );
		_mine_lastTables.css( "width" , options.width + "px" );

		var setWidthArray = computeWidth( options.widtharray , options.width )

		_mine_firstTable.find("TR:first TH,TD").each(function(i) {
			var H = $(this).html();
			$(this).css("width", setWidthArray[i]);
			$(this).html( "<span style='width:"+setWidthArray[i]+"'>"+H+"</span>" );
		});
		_mine_lastTables.find("TR").each(function(){
			$(this).find("TH,TD").each(function(i) {
				var H = $(this).html();
				$(this).css("width", setWidthArray[i]);
				$(this).html( "<span style='width:"+setWidthArray[i]+"'>"+H+"</span>" );
			});
		});
	}
	var color = function(){
		_mine.find("div.css_scroll tr").removeClass();
		_mine.find("div.css_scroll  tr:even").addClass("tr_double");	
	};
	var delbutten = function(){
		_mine.find("div.css_scroll .del" ).click(function(){
			$(this).parents("tr").eq(0).remove();
			color();
		});
	};
	//表格染色
	color();
	//激活删除按钮
	delbutten();
	//激活全选checkbox
	_mine.find(".check_all" ).click(function(){
		var state = $(this).is(":checked");
		_mine.find("div.css_scroll .check" ).attr( "checked",state );
	});

	return {
		//获取其中已有的数据
		getResult : function(){
			var result = '';
			_mine.find("#data tr").each(function(){
				if( $(this).is(":hidden") )return;
				var C = $(this).attr("content");
				result += '##'+C+"##";
			});
			return result.replace( /####/g , "," ).replace( /##/g , "" );
		},
		getResultNum : function(){
			var result = 0;
			_mine.find("#data tr").each(function(){
				if( $(this).is(":hidden") )return;
				result++;
			});
			return result;
		},
		activeDel : function( method ){
			_mine.find("#data .del" ).click(function(){
				method( $(this) );
			});
		},
		activeCheck : function( method ){
			_mine.find("#data .check:checkbox" ).click(function(){
				method( $(this) );
			});
		},
		clear : function( ){
			_mine.find("#data tr" ).remove();
		},
		addTr : function( dataArray ){
			if( dataArray.length < 1 ){ return; }
			var demo = _mine.find("div.css_scroll #demo").html();
			var H = "<TR content='"+dataArray[0]+"'>"
			for(var i = 1 , l = dataArray.length; i < l ; i++ ){
				demo = demo.replace( "###"+i+"###" , dataArray[i] );
			}
			H += demo+"</span>";
			_mine.find("#data").append( H );
			return;
		},
		addTrs : function( dataArrayII ){
			if( dataArrayII.length < 1 ){ return; }
			for(var i = 0 , l = dataArrayII.length; i < l ; i++ ){
				this.addTr( dataArrayII[i] );
			}
		},
		readJson : function( method ){
			var A = method();
			this.addTrs( A );
			color();
			delbutten();
			return;
		},
		addJson : function( method ){
			var A = method();
			this.addTr( A );
			color();
			delbutten();
			return;
		},
		setCheck : function( method ){
			var A = method();
			for(var i = 0 , l = A.length; i < l ; i++ ){
				var targle = _mine.find("[content="+A[i]+"]");
				if( targle.length>0 ){
					targle.find(".check").attr("checked",true);
					targle.find(".injoin").html( "已勾选" );
				}
			}
			return;
		},
		getSelected : function(){
			var result = '';
			_mine.find("#data tr").each(function(){
				if( $(this).is(":hidden") )return;
				if( $(this).find(".check").is(":checked") == false )return;
				var C = $(this).attr("content");
				result += '##'+C+"##";
			});
			return result.replace( /####/g , "," ).replace( /##/g , "" );
		},
		getSelectedNum : function(){
			var result = 0;
			_mine.find("#data tr").each(function(){
				if( $(this).is(":hidden") )return;
				if( $(this).find(".check").is(":checked") == false )return;
				result++;
			});
			return result;
		}
		
	};
}
function computeWidth(widthArray,widthTotal){
	var Warray=new Array();
	var Wtotal=parseInt(widthTotal);
	for(var i=0,l=widthArray.length;i<l;i++){
		if(widthArray[i].indexOf("%")==-1){
			Wtotal-=parseInt(widthArray[i])
		}
		Warray[i]=widthArray[i].replace("px","")
	}
	for(var	i=0,l=widthArray.length;i<l;i++){
		if(widthArray[i].indexOf("%")!=-1){
			Warray[i]=Math.floor(parseInt(widthArray[i])*Wtotal/100)
		}
		Warray[i]+="px";
	}
	Warray[Warray.length-1]="auto";
	return Warray;
}
//分页信息
function setPageLinkCustom(renderTo,page,callbackName){
	var last=(page.total <= page.count*page.page)?"<div class=\"dp_imglink_td\"><a href=\"javascript:void(0)\" class=\"imglink\" title=\"\"><img src=\"./images/lsec/datagrid/page-last-disabled.gif\"></a></div>":"<div class=\"dp_imglink_td\" onclick=\""+callbackName+"( "+parseInt(page.total/page.count+1)+" )\"><a href=\"javascript:void(0)\" class=\"imglink\" title=\"\"><img src=\"./images/lsec/datagrid/page-last.gif\"></a></div>";
	var next=(page.total <= page.count*page.page)?"<div class=\"dp_imglink_td\"><a href=\"javascript:void(0)\" class=\"imglink\" title=\"\"><img src=\"images/lsec/datagrid/page-next-disabled.gif\"></a></div>":"<div class=\"dp_imglink_td\" onclick=\""+callbackName+"( "+(parseInt(page.page)+1)+")\"><a href=\"javascript:void(0)\" class=\"imglink\" title=\"\"><img src=\"images/lsec/datagrid/page-next.gif\"></a></div>";
	var pageCode = "<div id=\"datagrid_pager\" class=\"datagrid_pager\"  style=\"position: relative; width: auto;\">"+
		"<div class=\"page_total\" style=\"float:left;\">Total:"+page.total+"</div>"+
		last+
		next+
		"<div class=\"dp_imglink_td\" style=\"margin-top:-3px;\"><span>Page of "+page.page+"</span>  </div>"+
		"<div class=\"dp_imglink_td\" onclick=\""+callbackName+"( "+(parseInt(page.page)-1)+")\"><a href=\"javascript:void(0)\" class=\"imglink\" title=\"\"><img src=\"images/lsec/datagrid/page-prev.gif\"></a>    </div>"+
		"<div class=\"dp_imglink_td\" onclick=\""+callbackName+"( 1)\"><a href=\"javascript:void(0)\" class=\"imglink\" title=\"\"><img src=\"images/lsec/datagrid/page-first.gif\"></a></div>"+
		"</div>";
	if(parseInt(page.total) < parseInt(page.count)&&page.total <= page.count*page.page)
	var pageCode = "<div id=\"datagrid_pager\" class=\"datagrid_pager\">"+
	"<div class=\"page_total\">Total:"+page.total+"</div>"+
	"</div>";
	$("#datagrid_pager").remove();
	$("#"+renderTo).append(pageCode);
}

var ERROE_MSG_LIST = {
	CANT_BE_NULL			:	'不能为空',
	IN_USED					:	'关键词已占用',
	STR_ILLEGAL				:	'输入内容不合法',
	STARTWITH1				:	'开头字符请用字母',
	STARTWITH2				:	'开头字符请用数字',
	STARTWITH3				:	'开头字符请用数字字母',
	STARTWITH4				:	'开头字符请用数字字母下划线',
	STARTWITH5				:	'开头字符请用数字字母下划线',
	STARTWITH6				:	'开头字符请用汉字数字字母@._-',
	START_NO_NUM			:	'首字符不能为数字',
	ONLY_NUMBER				:	'只允许输入数字',
	ONLY_LETTER				:	'只允许输入字母',
	ALLOW3					:	'请输入合法字符,例如:数字字母',
	ALLOW4					:	'请输入合法字符,例如:数字字母下划线',
	ALLOW51					:	'请输入合法字符,例如:汉字数字字母',
	ALLOW52					:	'请输入合法字符,例如:汉字数字字母以及空格',
	ALLOW5					:	'请输入合法字符,例如:汉字数字字母以及@._-()[]|',
	ALLOW6					:	'请输入合法字符,例如:数字字母以及@._-',
	ALLOW7					:	'请输入合法字符,不能输入空格',
	NO_CHINESE				:	'不能使用汉字',
	PD_IS_DIFFERENT			:	'前后密码不一致',
	IP_ILLEGAL				:	'输入ip格式不正确',
	IP_WORNG				:	'输入ip不合法',
	MASK_ILLEGAL			:	'掩码不合法',
	MAC_ILLEGAL				:	'MAC不合法',
	MUST_HEX				:	'请输入十六进制格式',
	OUT_OF_RANGE			:	'数字超出范围',
	STR_TOO_SHORT			:	'输入信息过短',
	STR_TOO_LONG	 		:	'输入信息过长',
	EMAIL_ILLEGAL			:	'格式错误',
	OUT_OF_SPACE			:	'范围总数超出范围',
	SPACE_MUST_ASC		:	'后者须大于前者',
	LENGTH_MUST_BE		:	'请限制长度为 XXX 个字符',

	COMBOTREE_MUST_SELECT_ONE : '请配置至少一项',
	COMBOTREE_SET_MAX : '请配置最多四项',
	ALLOW_NUMBER_OR_FLOAT:	'格式有误'
};
//验证机器,全局初始化
$.validator = {
	//debug模式 1未开启,0为关闭
	debugMode : 0,
	//有组织有计划的开始验证
	textChecking : function( $value , checkListOne ){
		var checkOne = checkListOne.toLowerCase( );
		var checkType = checkOne.match( /^[a-zA-Z]*/ ).toString( );
		switch( checkType ){

			//必填
			case( 'notnull' ):
			case( 'must' ):
				if( $value === '' || $value === null ) return( ERROE_MSG_LIST.CANT_BE_NULL );
				break;

			//非必填
			case( 'allownull' ):
			case( 'null' ):
				if( $value === '' ) return ('=s=');
				break;

			//指定认为正确的例子
			case( 'right' ):
			case( 'legal' ):
				if( checkOne.replace( 'right:','' ).replace( 'legal:','' ) === $value ) return ('=s=');
				break;

			//指定认为错误的例子
			case( 'wrong' ):
			case( 'illegal' ):
				if( checkOne.replace( 'wrong:','' ).replace( 'illegal:','' ) === $value ) return( ERROE_MSG_LIST.STR_ILLEGAL );
				break;

			//起始字符指定字母开头
			case( 'startwithl' ):
			case( 'startwithletter' ):
				if( ! /^[a-zA-Z]/.test( $value ) ) return( ERROE_MSG_LIST.STARTWITH1 );
				break;

			//起始字符指定数字开头
			case( 'startwithn' ):
			case( 'startwithnumber' ):
				if( ! /^[0-9]/.test( $value ) ) return( ERROE_MSG_LIST.STARTWITH2 );
				break;

			//起始字符指定数字字母开头
			case( 'startwithln' ):
			case( 'startwithletternumber' ):
				if( ! /^[a-zA-Z0-9]/.test( $value ) ) return( ERROE_MSG_LIST.STARTWITH3 );
				break;

			//起始字符指定数字字母下划线开头
			case( 'startwithlnu' ):
			case( 'startwithletternumberunderline' ):
				if( ! /^[a-zA-Z0-9_]/.test( $value ) ) return( ERROE_MSG_LIST.STARTWITH4 );
				break;

			//起始字符可以为 数字字母汉字
			case( 'startwithlnuc' ):
			case( 'startwithletternumbercn' ):
				if( ! /^[a-zA-Z0-9_]/.test( $value ) ) return( ERROE_MSG_LIST.STARTWITH5 );
				break;

			//起始字符可以为 汉字数字字母@._-
			case( 'startwithname1' ):
				if( ! /^[\u4e00-\u9fafa-zA-Z0-9@._-]/.test( $value ) ) return( ERROE_MSG_LIST.STARTWITH6 );
				break;

			//起始字符可以为 非数字
			case( 'startwithnon' ):
			case( 'start_no_number' ):
				if( /^[0-9]/.test( $value ) ) return( ERROE_MSG_LIST.START_NO_NUM );
				break;

			//可用字符须为数字
			case( 'allown' ):
			case( 'allownumber' ):
				if( ! /^[0-9]*$/.test( $value ) ) return( ERROE_MSG_LIST.ONLY_NUMBER );
				break;
			
			//组成字符串浮点型.
			case( 'allowfloat' ):
				if( ! /^[0-9.]*$/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW_NUMBER_OR_FLOAT);
				break;

			//组成字符串只能是数字 0-9和.
			case( 'allowip' ):
				if( ! /^[0-9.]*$/.test( $value ) ) return( ERROE_MSG_LIST.IPwORING );
				break;

			//组成字符串只能是字母 a-zA-Z
			case( 'allowl' ):
			case( 'allowletter' ):
				if( ! /^[a-zA-Z]*$/.test( $value ) ) return( ERROE_MSG_LIST.ONLY_LETTER );
				break;

			//组成字符串可以为 数字字母
			case( 'allowln' ):
			case( 'allowletternumber' ):
				if( ! /^[a-zA-Z0-9]*$/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW3 );
				break;

			//组成字符可以为 数字字母下划线
			case( 'allowlnu' ):
			case( 'allowletternumberunderline' ):
				if( ! /^[a-zA-Z0-9_]*$/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW4 );
				break;

			//可用字符指定数字字母汉字allowLetterNumberChinese || allowLNC
			case( 'allowletternumberchinese' ):
			case( 'allowlnc' ):
				if( ! /^[\u4e00-\u9fafa-zA-Z0-9]*$/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW51 );
				break;

			//可用字符指定数字字母汉字空格allowLetterNumberChineseSpace || allowLNCS
			case( 'allowletternumberchinesespace' ):
			case( 'allowlncs' ):
				if( ! /^[\u4e00-\u9fafa-zA-Z0-9 ]*$/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW52 );
				break;

			//组成字符可以为 汉字数字字母@._-
			case( 'allowname' ):
				if( ! /^[\u4e00-\u9fafa-zA-Z0-9@._\-\|\(\)\[\]]*$/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW5 );
				break;

			case( 'nospace' ):
				if( /\s/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW7 );
				break;

			//组成字符可以为 数字字母@._-
			case( 'allowcode' ):
				if( ! /^[a-zA-Z0-9@._-]*$/.test( $value ) ) return( ERROE_MSG_LIST.ALLOW5 );
				break;

			//组成字符可以为 非汉字
			case( 'nocn' ):
			case( 'no_chinese' ):
				if( /[\u4e00-\u9faf]/.test( $value ) ) return( ERROE_MSG_LIST.NO_CHINESE );
				break;

			//密码验证,判断是否与另一个相符合
			case( 'password' ):
				var repw = checkOne.replace( 'password:','' );
				if( $( '#'+repw ).val( ) !== $value ) return( ERROE_MSG_LIST.PD_IS_DIFFERENT );
				break;

			//IP合法性检验
			case( 'ip' ):
				if( /^\d{1,3}(\.\d{1,3}){3}$/.test( $value ) ){
					var ary = $value.split( '.' );
					for(var i = 0 ; i < 4 ; i++ ){
						if( parseInt( ary[i] ) > 255 ) return( ERROE_MSG_LIST.IP_ILLEGAL );
					}
					//去掉组播地址和多播地址,结束不能为0 255
					//if( parseInt( ary[0] ) == 127 || parseInt( ary[0] ) > 223 || parseInt( ary[3] ) < 1 ||  parseInt( ary[3] ) > 254 ){
					//	return( ERROE_MSG_LIST.IP_WORNG );
					//}
					return ('');
				}else return( ERROE_MSG_LIST.IP_ILLEGAL );
				break;
			case( 'subnet' ):
				if(/^\d{1,3}(\.\d{1,3}){3}\/\d{1,2}$/.test( $value )){
					var a = $value.split("/");
					var ipa = a[0].split( '.' );
					for(var i = 0 ; i < 4 ; i++ ){
						if( parseInt( ipa[i] ) > 255 ) return( ERROE_MSG_LIST.IP_ILLEGAL );
					}
					//if( parseInt( ipa[0] ) == 127 || parseInt( ipa[0] ) > 223 || parseInt( ipa[3] ) < 1 ||  parseInt( ipa[3] ) > 254 )
					//	return( ERROE_MSG_LIST.IP_ILLEGAL );
					if( (parseInt( a[1] ) > 32 ||  parseInt( a[1] ) < 8) && parseInt( a[1] ) != 0){
						return( ERROE_MSG_LIST.MASK_ILLEGAL );
					}
					return( "" );
				}else{
					return( ERROE_MSG_LIST.IP_ILLEGAL );
				}
				break;

			//IP/域名合法性检验
			case( 'ipdn' ):
				if( /^\d{1,3}(\.\d{1,3}){3}$/.test( $value ) ){
					var ary = $value.split( '.' );
					for( key in ary ){
						if( parseInt( ary[key] ) > 255 ) return( ERROE_MSG_LIST.IP_OUT_OF_RANGE );
					}
				}else return( ERROE_MSG_LIST.IP_ILLEGAL );
				break;

			//email格式检验
			case( 'email' ):
				if( ! /^( [a-zA-Z0-9]+[_|\_|\.]? )*[a-zA-Z0-9]+@( [a-zA-Z0-9]+[_|\_|\.]? )*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test( $value ) ) 
				return( ERROE_MSG_LIST.EMAIL_ILLEGAL );
				break;

			//mask检验,并转化为2进
			case( 'maskp' ):
				if( /^[0-9]*$/.test( $value ) && parseInt( $value ) < 33 ){
					var a = parseInt( $value ) ,targle = '' ,b = Math.floor(a/8),narray = [ '0','128','192','224','240','248','252','254','255'];
					for( var c = b ; c > 0 ; c-- ){ targle += '255.'; }
					if( b < 4 ){ targle += narray[ a%8 ]+'.'; }
					if( b < 3 ){ for( var d = 3-b ; d > 0 ; d-- ){targle += '0.';} }
					return "=v=" + targle.replace( /\.$/g , '' ) ;
				}else if( /^\d{1,3}(.\d{1,3}){3}$/.test( $value ) ){
					var x = $value.split(".");
					$value = parseInt(x[0])+"."+parseInt(x[1])+"."+parseInt(x[2])+"."+parseInt(x[3]);
					if( /^(255.){0,3}(255||254||252||248||240||224||192||128||0)(.0){0,3}$/.test( $value ) ){
						return "=v=" + $value ;
					}
					return( ERROE_MSG_LIST.MASK_ILLEGAL );
				}else return( ERROE_MSG_LIST.MASK_ILLEGAL );
				break;

			//mask检验
			case( 'mask' ):
				if( /^\d{1,3}(.\d{1,3}){3}$/.test( $value ) 
					&& /^(255.){0,3}(255||254||252||248||240||224||192||128||0)(.0){0,3}$/.test( $value ) ){
					return "";
				}
				else if( /^[0-9]*$/.test( $value ) && parseInt( $value ) < 33 ){
					return "";
				}
				else return( ERROE_MSG_LIST.MASK_ILLEGAL );
				break;

			//mac地址检验
			case( 'mac' ):
				if( ! /[a-fA-F\d]{1,2}-[a-fA-F\d]{1,2}-[a-fA-F\d]{1,2}-[a-fA-F\d]{1,2}-[a-fA-F\d]{1,2}-[a-fA-F\d]{1,2}/.test( $value ) ) 	
					return( ERROE_MSG_LIST.MAC_ILLEGAL );
				break;

			//数字范围的正则校验
			case( 'range' ):
				$value = parseInt( $value );
				var a = checkOne.replace( 'range:' , '' ).split( '-' );
				if( $value < parseInt(a[0]) || $value > parseInt(a[1]) ) return( ERROE_MSG_LIST.OUT_OF_RANGE );
				break;

			//范围总数
			case( 'space' ):
				if( ! /^[0-9]*$/.test( $value ) ) return( ERROE_MSG_LIST.ONLY_NUMBER );
				var a = checkOne.replace( 'space:' , '' ).split( '@' );
				$value = parseInt( $value );
				var $value2 = parseInt( $("#"+a[1]).val() );
				if( ! /^[0-9]*$/.test( $value2 ) ) return( ERROE_MSG_LIST.ONLY_NUMBER );
				if( $value2 < $value ) return( ERROE_MSG_LIST.SPACE_MUST_ASC );
				var space = Math.abs( $value2 - $value );
				if( space > a[0] ) return( ERROE_MSG_LIST.OUT_OF_SPACE );
				break;

			//字符串长度
			case( 'length' ):
				var a = checkOne.replace( 'length:' , '' ).split( '-' );
				if( $value.length < a[0] ) return( ERROE_MSG_LIST.STR_TOO_SHORT );
				else if( $value.length > a[1] ) return( ERROE_MSG_LIST.STR_TOO_LONG );
				break;

			//长度指定
			case( 'lengthmust' ):
				var a = checkOne.replace( 'lengthmust:' , '' );
				if( $value.length != a ) return( ERROE_MSG_LIST.LENGTH_MUST_BE.replace( 'xxx' , a ) );
				break;

			//十六进制格式
			case( 'hex' ):
				if( ! /^[0-9a-fA-F]*$/.test( $value ) ) return( ERROE_MSG_LIST.MUST_HEX );
				break;
		}
		return '';
	},
	combotreeChecking : function( $value , checkListOne ){
		var checkOne = checkListOne.toLowerCase( );
		var checkType = checkOne.match( /^[a-zA-Z]*/ ).toString( );
		switch( checkType ){
			case( 'must' ):
				if( $value.length < 1 )return( ERROE_MSG_LIST.COMBOTREE_MUST_SELECT_ONE );
				break;
			case( 'max' ):
				if( $value.length > parseInt( checkOne.replace('max:','') ) )return( ERROE_MSG_LIST.COMBOTREE_SET_MAX );
				break;
		}
		return "";
	},
	//根据控件类型进行分类验证
	checkStr : function( type , $value , checkListOne ){
		if( type == "text" || type == "ipbox"  ){
			return $.validator.textChecking( $value , checkListOne );
		}else if( type == "combotree" ){
			return $.validator.combotreeChecking( $value , checkListOne );
		}
	}
};
//检查方法
$.fn.checkInput = function( options ){

	var defaults = {
		tip :'no',										/* 常用 用来指示错误出自哪个业务控件 */
		cl : ['Must'],								/* 按照顺序进行校验,使提示更加精准 */
		el : [],											/* 可自定以对应的错误提示,保持原来请留空串值 */
		type:'text'									/* 类型控制,一般来说不用理会,针对其他控件例如下拉树,ipbox等 */
	};	
	var options = $.extend( defaults , options );
	var mine = $( this ),myValue = '';

	//重新设置值
	var resetValue = function( value ){
		mine.val( value );
	};
	
	//错误提示
	var errorBreak = function( errorMessage ){
		/* 结束检查,如果有错,处理错误返回false并提示 */
		if( errorMessage !== '' ) {
			if( options.tip != "no" ){
				errorMessage = options.tip +' : '+ errorMessage + ' !'
			}
			//alert( errorMessage );
			mine.focus( );

			//当次输入框改变内容后即取消掉错误显示 by liuyp 临时解决方法
			mine.keyup(function(){
				mine.next("span.error").html("");
			});

			
			if( mine.next("span.error").length >0 ){
				mine.next("span.error").html( errorMessage );
			}else{
				if( options.cl[3] == 'alert' )
					alert(errorMessage)
				else
					mine.after( "<span class='error'>"+errorMessage+"</span>" );
			}
			return false;
		}
		return true;
	};

	if( mine.attr( 'box' ) == 'ip' ){
		myValue = mine.ipBox().val();
		options.type = "ipbox";
	}else if( mine.hasClass('easyui-combotree') ){
		myValue = mine.combotree( "getValues" );
		options.type = "combotree";
	}else{
		myValue = mine.val();
	}

	for( var i = 0 , l = parseInt( options.cl.length ) ; i < l ; i++ ){
		//遍历验证
		var result = $.validator.checkStr( options.type , myValue , options.cl[i] );
		//验证结果,有信息就是出错了
		if ( result !== '' && result !== undefined ){
			if( /^=s=/.test( result ) ) {
				return true;
			}else if( /^=v=/.test( result ) ) {
				resetValue( result.replace("=v=","") );
			}else if( options.el.length > i && options.el[i] != '' ){
				return errorBreak( options.el[i] );
			}else {
				return errorBreak( result );
			}
		}
	}

	return true;
}
//检查前后ip是否前大后小
function checkIpRange( XID , YID ){
	var x = $("#"+XID).val(),y = $("#"+YID).val();
	return checkIpRangeVal( x , y );
}

function checkIpRangeVal( x , y , show){
	var a = x.split(".") , b = y.split(".") 
	for ( var i =0;i<4;i++  ){
		if(  parseInt( a[i] )  >  parseInt( b[i] ) ){
			//$(XID).focus();
			if( show == undefined ){alert( "请确认起始ip应小于结束ip !" );}
			return false;
		}else if(  parseInt( a[i] )  <  parseInt( b[i] ) ){
			return true;
		}
	}
	return true;
}

function checkIPnew( str ){
	if( /^\d{1,3}(\.\d{1,3}){3}$/.test( str ) ){
		var ipa = str.split(".");
		for(var i = 0 ; i < 4 ; i++ ){
			if( parseInt( ipa[i] ) > 255 ) return false;
		}
		//if( parseInt( ipa[0] ) == 127 || parseInt( ipa[0] ) > 223 || parseInt( ipa[3] ) < 1 ||  parseInt( ipa[3] ) > 254 ){
		//	return false;
		//}
		return true;
	}
	return false;
}
function checkMasknew(str){
	if( /^[0-9]*$/.test( str ) && parseInt( str ) < 33 && parseInt( str ) >= 0 ){
		return true;
	}else if( /^\d{1,3}(\.\d{1,3}){3}$/.test( str ) 
		&& /^(255.){1,3}(255||254||252||248||240||224||192||128||0)(.0){1,3}$/.test( str ) ){
		return true;
	}
	return false;
}
function checkAllIP(str){

	if( str.indexOf("-") > 0 ){
		var ipA = str.split("-");
		if( checkIPnew(ipA[0]) && checkIPnew(ipA[1]) && checkIpRangeVal(ipA[0],ipA[1]) ) return true;
		return false;
	}else if( str.indexOf("/") > 0 ){
		var ipB = str.split("/");
		if( checkIPnew(ipB[0]) && checkMasknew(ipB[1]) ) return true;
		return false;
	}else{
		var ipC = str;
		if( checkIPnew(ipC) ) return true;
		return false;
	}
	return false;
}
function word_format(content,interval) {
	var num = 0,contentval = '';
	for (var i = 0; i < content.length; i++) {
		if (/^[a-zA-Z0-9]*$/.test(content.charAt(i))) { //这是判断英文、数字的正则表达式
			num += 1;
			contentval += content.charAt(i);
		} else if (/^[\u4e00-\u9fa5]*$/.test(content.charAt(i)) || /^[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]*$/.test(content.charAt(i))) { //这是判断中文和中文符号的正则表达式
			num += 2;
			contentval += content.charAt(i);
		} else { //其它字符截字
			contentval += content.charAt(i);
			num += 1;
		}
		//对num取余每隔interval个字符加上换行符号
		if (num % interval == 0) {
			contentval += "<br/>";
		}
	}
	return contentval;
}

function chk_Disabled_Element_Fun(src,dst){
	if($('#' + src).attr('checked') == 'checked'){
		for(var i = 0 ; i < dst.length ; i++){
			$('#' + dst[i]).removeAttr('disabled');
		}
	}else{
		for(var i = 0 ; i < dst.length ; i++){
			$('#' + dst[i]).attr('disabled','disabled');
		}
	}
}